package com.ys.homework;

/**
 * 描述: 书类
 *
 * @author CodeYang
 * @version 2020/12/15 21:37
 */
public class Book {
    /**
     * 书名
     */
    private String name;
    /**
     * 作者
     */
    private String author;
    /**
     * 出版社
     */
    private String press;
    /**
     * 价格
     */
    private double price;

    public Book() {
    }

    public Book(String name, String author, String press, double price) {
        this.name = name;
        this.author = author;
        this.press = press;
        this.setPrice(price);
//        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getPress() {
        return press;
    }

    public void setPress(String press) {
        this.press = press;
    }

    public double getPrice() {
        return price;
    }

    /**
     * 设置价格: 价格不能低于10 元,否则为10元 并提示
     *
     * @param price
     */
    public void setPrice(double price) {
        this.price = price < 10 ? 10 : price;
        if (price < 10) {
            System.out.println("价格不能低于10元,已经设为默认值:10元");
        }
    }

    public void showInfo() {
        System.out.println("书名='" + name + '\n' +
                "作者='" + author + '\n' +
                "出版社='" + press + '\n' +
                "价格=" + price);
    }


}
